home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-09-06 | 12.2 KB | 486 lines | [TEXT/CWIE] |
- // TabbedPanel.cp
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Appearance.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "DoScrap.h"
- #include "Miscellany.h"
- #include "Scrolling.h"
- #include "ControlUtils.h"
- #include "DDocData.h"
- #include "GadgetsEngine.h"
- #include "GadgetsDoc.h"
-
- #include "TabbedPanel.h"
-
-
- //----------
- void TabbedPanel::Create (
- AMDoc* inDoc,
- DDocData* inData)
- {
- TabbedPanel* winObj = new TabbedPanel;
-
- if (winObj != nil) {
- winObj->Open (inDoc);
- winObj->ConnectToData (inData);
- }
- }
-
- //----------
- TabbedPanel::TabbedPanel ()
- {
- mData = nil;
- }
-
- //----------
- TabbedPanel::~TabbedPanel ()
- {
- }
-
- //----------
- GadgetsEngine* TabbedPanel::GetEngine ()
- {
- return (GadgetsEngine*) mDoc->mEngine;
- }
-
- //----------
- void TabbedPanel::Open (
- AMDoc* inDoc)
- {
- WindowPtr window;
- Handle wftb;
-
- mDoc = inDoc;
-
- window = GetNewCWindow (WIND_TabbedPanel, nil, (WindowPtr) -1L);
- if (mDoc->mEngine->GetFilename () [0] != 0) {
- SetWTitle (window, mDoc->mEngine->GetFilename ());
- }
- mWindow = window;
- ((GadgetsDoc*)mDoc)->mTabbedPanelPtr = window;
-
- SetWindowKind (window, 'AM');
- SetWRefCon (window, (long) this);
- SetPort (window);
- SetInfo (window);
-
- wftb = ::GetResource ('Wftb', WIND_TabbedPanel);
-
- CreateRootControl (window, &mRootControl);
-
- vScroll = nil;
- hScroll = nil;
-
-
- mBarsHandle = ::GetNewControl (CNTL_Bars, window);
- SetWindowItemFont (mBarsHandle, wftb, 1);
-
-
- mScrollBarsHandle = ::GetNewControl (CNTL_ScrollBars, window);
- EmbedControl (mScrollBarsHandle, mBarsHandle);
- SetWindowItemFont (mScrollBarsHandle, wftb, 2);
-
- mStandard2Handle = ::GetNewControl (CNTL_Standard2, window);
- EmbedControl (mStandard2Handle, mScrollBarsHandle);
- SetWindowItemFont (mStandard2Handle, wftb, 3);
-
- mGraphicHandle = ::GetNewControl (CNTL_Graphic, window);
- EmbedControl (mGraphicHandle, mScrollBarsHandle);
- SetWindowItemFont (mGraphicHandle, wftb, 4);
-
- mSliderHandle = ::GetNewControl (CNTL_Slider, window);
- EmbedControl (mSliderHandle, mScrollBarsHandle);
- SetWindowItemFont (mSliderHandle, wftb, 5);
-
- mTickMarksHandle = ::GetNewControl (CNTL_TickMarks, window);
- EmbedControl (mTickMarksHandle, mScrollBarsHandle);
- SetWindowItemFont (mTickMarksHandle, wftb, 6);
-
- mNonDirectionalHandle = ::GetNewControl (CNTL_NonDirectional, window);
- EmbedControl (mNonDirectionalHandle, mScrollBarsHandle);
- SetWindowItemFont (mNonDirectionalHandle, wftb, 7);
-
- mLittleArrowsHandle = ::GetNewControl (CNTL_LittleArrows, window);
- EmbedControl (mLittleArrowsHandle, mScrollBarsHandle);
- SetWindowItemFont (mLittleArrowsHandle, wftb, 8);
-
- mSpinnerHandle = ::GetNewControl (CNTL_Spinner, window);
- EmbedControl (mSpinnerHandle, mScrollBarsHandle);
- SetWindowItemFont (mSpinnerHandle, wftb, 9);
-
- mVolumeControlHandle = ::GetNewControl (CNTL_VolumeControl, window);
- EmbedControl (mVolumeControlHandle, mScrollBarsHandle);
- SetWindowItemFont (mVolumeControlHandle, wftb, 10);
-
- mJimSSliderHandle = ::GetNewControl (CNTL_JimSSlider, window);
- EmbedControl (mJimSSliderHandle, mScrollBarsHandle);
- SetWindowItemFont (mJimSSliderHandle, wftb, 11);
-
-
- mProgressBarsHandle = ::GetNewControl (CNTL_ProgressBars, window);
- EmbedControl (mProgressBarsHandle, mBarsHandle);
- SetWindowItemFont (mProgressBarsHandle, wftb, 12);
-
- mStandard3Handle = ::GetNewControl (CNTL_Standard3, window);
- EmbedControl (mStandard3Handle, mProgressBarsHandle);
- SetWindowItemFont (mStandard3Handle, wftb, 13);
-
- mIndeterminateHandle = ::GetNewControl (CNTL_Indeterminate, window);
- EmbedControl (mIndeterminateHandle, mProgressBarsHandle);
- SetWindowItemFont (mIndeterminateHandle, wftb, 14);
- SetIndeterminateState (mIndeterminateHandle, true);
-
- mChasingArrowsHandle = ::GetNewControl (CNTL_ChasingArrows, window);
- EmbedControl (mChasingArrowsHandle, mProgressBarsHandle);
- SetWindowItemFont (mChasingArrowsHandle, wftb, 15);
-
- mRectangleHandle = ::GetNewControl (CNTL_Rectangle, window);
- EmbedControl (mRectangleHandle, mProgressBarsHandle);
- SetWindowItemFont (mRectangleHandle, wftb, 16);
-
- mRoundRectHandle = ::GetNewControl (CNTL_RoundRect, window);
- EmbedControl (mRoundRectHandle, mProgressBarsHandle);
- SetWindowItemFont (mRoundRectHandle, wftb, 17);
-
- mBarberPoleHandle = ::GetNewControl (CNTL_BarberPole, window);
- EmbedControl (mBarberPoleHandle, mProgressBarsHandle);
- SetWindowItemFont (mBarberPoleHandle, wftb, 18);
-
- mRoundBarberHandle = ::GetNewControl (CNTL_RoundBarber, window);
- EmbedControl (mRoundBarberHandle, mProgressBarsHandle);
- SetWindowItemFont (mRoundBarberHandle, wftb, 19);
-
- AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- }
-
- //----------
- void TabbedPanel::Close ()
- {
- mData->RemoveResponder (this);
-
- ((GadgetsDoc*)mDoc)->mTabbedPanelPtr = nil;
- SetInfo (nil);
- HideWindow (mWindow);
- DisposeWindow (mWindow);
-
- delete this;
- }
-
- //----------
- void TabbedPanel::ConnectToData (
- DDocData* inData)
- {
- mData = inData;
- mData->AddResponder (this);
-
- SetControlValue (mBarsHandle, mData->GetBars ());
- SetLayerGroupValue (mBarsHandle, GetControlValue (mBarsHandle));
- SetControlValue (mStandard2Handle, mData->GetStandard2 ());
- SetControlValue (mGraphicHandle, mData->GetGraphic ());
- SetControlValue (mSliderHandle, mData->GetSlider ());
- SetControlValue (mTickMarksHandle, mData->GetTickMarks ());
- SetControlValue (mNonDirectionalHandle, mData->GetNonDirectional ());
- SetControlValue (mLittleArrowsHandle, mData->GetLittleArrows ());
- SetControlValue (mSpinnerHandle, mData->GetSpinner ());
- SetControlValue (mVolumeControlHandle, mData->GetVolumeControl ());
- SetControlValue (mJimSSliderHandle, mData->GetJimSSlider ());
- SetControlValue (mStandard3Handle, mData->GetStandard3 ());
- SetControlValue (mIndeterminateHandle, mData->GetIndeterminate ());
- SetControlValue (mChasingArrowsHandle, mData->GetChasingArrows ());
- SetControlValue (mRectangleHandle, mData->GetRectangle ());
- SetControlValue (mRoundRectHandle, mData->GetRoundRect ());
- SetControlValue (mBarberPoleHandle, mData->GetBarberPole ());
- SetControlValue (mRoundBarberHandle, mData->GetRoundBarber ());
- }
-
- //----------
- void TabbedPanel::DataChanged (
- long inDataID)
- {
- if (inDataID == idBars) {
- SetControlValue (mBarsHandle, mData->GetBars ());
- SetLayerGroupValue (mBarsHandle, mData->GetBars ());
- }
- if (inDataID == idStandard2) {
- SetControlValue (mStandard2Handle, mData->GetStandard2 ());
- }
- if (inDataID == idGraphic) {
- SetControlValue (mGraphicHandle, mData->GetGraphic ());
- }
- if (inDataID == idSlider) {
- SetControlValue (mSliderHandle, mData->GetSlider ());
- }
- if (inDataID == idTickMarks) {
- SetControlValue (mTickMarksHandle, mData->GetTickMarks ());
- }
- if (inDataID == idNonDirectional) {
- SetControlValue (mNonDirectionalHandle, mData->GetNonDirectional ());
- }
- if (inDataID == idLittleArrows) {
- SetControlValue (mLittleArrowsHandle, mData->GetLittleArrows ());
- }
- if (inDataID == idSpinner) {
- SetControlValue (mSpinnerHandle, mData->GetSpinner ());
- }
- if (inDataID == idVolumeControl) {
- SetControlValue (mVolumeControlHandle, mData->GetVolumeControl ());
- }
- if (inDataID == idJimSSlider) {
- SetControlValue (mJimSSliderHandle, mData->GetJimSSlider ());
- }
- if (inDataID == idStandard3) {
- SetControlValue (mStandard3Handle, mData->GetStandard3 ());
- }
- if (inDataID == idIndeterminate) {
- SetControlValue (mIndeterminateHandle, mData->GetIndeterminate ());
- }
- if (inDataID == idChasingArrows) {
- SetControlValue (mChasingArrowsHandle, mData->GetChasingArrows ());
- }
- if (inDataID == idRectangle) {
- SetControlValue (mRectangleHandle, mData->GetRectangle ());
- }
- if (inDataID == idRoundRect) {
- SetControlValue (mRoundRectHandle, mData->GetRoundRect ());
- }
- if (inDataID == idBarberPole) {
- SetControlValue (mBarberPoleHandle, mData->GetBarberPole ());
- }
- if (inDataID == idRoundBarber) {
- SetControlValue (mRoundBarberHandle, mData->GetRoundBarber ());
- }
- }
-
- //----------
- void TabbedPanel::Control (
- ControlHandle whichControl,
- short whichPart,
- Point where)
- {
- Rect bounds;
- short newValue;
-
- ExitCurField ();
-
- if (whichControl == mBarsHandle) {
- if (TrackClick (mBarsHandle, where) != 0) {
- mData->SetBars (GetControlValue (mBarsHandle));
- }
- }
- if (whichControl == mStandard2Handle) {
- HandleControlClick (mStandard2Handle, where, curEvent.modifiers, nil);
- mData->SetStandard2 (GetControlValue (mStandard2Handle));
- }
- if (whichControl == mGraphicHandle) {
- HandleControlClick (mGraphicHandle, where, curEvent.modifiers, nil);
- mData->SetGraphic (GetControlValue (mGraphicHandle));
- }
- if (whichControl == mSliderHandle) {
- HandleControlClick (mSliderHandle, where, curEvent.modifiers, nil);
- mData->SetSlider (GetControlValue (mSliderHandle));
- }
- if (whichControl == mTickMarksHandle) {
- HandleControlClick (mTickMarksHandle, where, curEvent.modifiers, nil);
- mData->SetTickMarks (GetControlValue (mTickMarksHandle));
- }
- if (whichControl == mNonDirectionalHandle) {
- HandleControlClick (mNonDirectionalHandle, where, curEvent.modifiers, nil);
- mData->SetNonDirectional (GetControlValue (mNonDirectionalHandle));
- }
- if (whichControl == mLittleArrowsHandle) {
- HandleControlClick (mLittleArrowsHandle, where, curEvent.modifiers, nil);
- mData->SetLittleArrows (GetControlValue (mLittleArrowsHandle));
- }
- if (whichControl == mSpinnerHandle) {
- HandleControlClick (mSpinnerHandle, where, curEvent.modifiers, nil);
- mData->SetSpinner (GetControlValue (mSpinnerHandle));
- }
- if (whichControl == mVolumeControlHandle) {
- HandleControlClick (mVolumeControlHandle, where, curEvent.modifiers, nil);
- mData->SetVolumeControl (GetControlValue (mVolumeControlHandle));
- }
- if (whichControl == mJimSSliderHandle) {
- HandleControlClick (mJimSSliderHandle, where, curEvent.modifiers, nil);
- mData->SetJimSSlider (GetControlValue (mJimSSliderHandle));
- }
- }
-
- //----------
- void TabbedPanel::MouseIn (
- Point where,
- short modifiers)
- {
- Rect bounds;
-
- }
-
- //----------
- void TabbedPanel::ExitCurField ()
- {
- ControlHandle focus;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if (focus == nil) {
- // nothing to exit
-
- }
- }
-
- //----------
- void TabbedPanel::TypeIn (
- char ch)
- {
- ControlHandle focus;
- SInt16 keyCode;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if ((ch == charEnter)
- || (ch == charReturn)) {
- ExitCurField ();
- } else if (ch == charEsc) {
- } else if (ch == charTab) {
- DoTab ((curEvent.modifiers & optionKey) != 0);
- } else if (focus != nil) {
- keyCode = (SInt16)(curEvent.message & keyCodeMask);
- HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
- mDoc->mEngine->SetDirty ();
- } else {
- SysBeep (1);
- }
- }
-
- //----------
- void TabbedPanel::Resize ()
- {
- /* application-specific code to resize items in window */
- }
-
- //----------
- void TabbedPanel::Scroll (
- short newValue,
- short oldValue)
- {
- /* application-specific code to scroll window */
- if (gWhichScroll == vScroll) {
- } else { // horizontal
- }
- }
-
- //----------
- void TabbedPanel::DoUndo ()
- {
- } // DoUndo
-
- //----------
- void TabbedPanel::DoCut ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECut (curTE);
- mDoc->mEngine->SetDirty ();
- scrapDirty = true;
- }
- } // DoCut
-
- //----------
- void TabbedPanel::DoCopy ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECopy (curTE);
- scrapDirty = true;
- }
- } // DoCopy
-
- //----------
- void TabbedPanel::DoPaste ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEPaste (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoPaste
-
- //----------
- void TabbedPanel::DoClear ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEDelete (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoClear
-
- //----------
- void TabbedPanel::DoSelectAll ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TESetSelect (0, 32767, curTE);
- }
- } // DoSelectAll
-
- //----------
- void TabbedPanel::DoShowClipboard ()
- {
- } // DoShowClipboard
-
- //----------
- Boolean TabbedPanel::DoCommand (
- long inCommand)
- {
- Boolean result = true;
-
- switch (inCommand) {
- case cmdUndo:
- DoUndo ();
- break;
- case cmdCut:
- DoCut ();
- break;
- case cmdCopy:
- DoCopy ();
- break;
- case cmdPaste:
- DoPaste ();
- break;
- case cmdClear:
- DoClear ();
- break;
- case cmdSelectAll:
- DoSelectAll ();
- break;
- case cmdShowClipboard:
- DoShowClipboard ();
- break;
-
- default:
- result = false;
- } // switch
-
- return result;
- }
-